package jse;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class TestBirthDay {
	public static void main(String[] args) throws ParseException {
		String id="150426199211131111";
		System.out.println(getBirthDay(id));
	}
	
	public  static int getBirthDay(String id) throws ParseException{
		String date=id.substring(6,14);
		SimpleDateFormat fmt=new  SimpleDateFormat("yyyyMMdd");
		Date birthDay=fmt.parse(date);
		System.out.println(birthDay);
		Calendar cal=new GregorianCalendar();
		cal.setTime(birthDay);
		Calendar now=new GregorianCalendar();
		int age=now.get(Calendar.YEAR)-cal.get(Calendar.YEAR);
		cal.set(Calendar.YEAR,now.get(Calendar.YEAR));
		if(cal.compareTo(now)>0){
			age--;
		}
		return age;
		
	}
}
